/**HEADER********************************************************************
* 
* Copyright (c) 2008 Freescale Semiconductor;
* All Rights Reserved
*
* Copyright (c) 2004-2010 Embedded Access Inc.;
* All Rights Reserved
*
* Copyright (c) 1989-2008 ARC International;
* All Rights Reserved
*
*************************************************************************** 
*
* THIS SOFTWARE IS PROVIDED BY FREESCALE "AS IS" AND ANY EXPRESSED OR 
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  
* IN NO EVENT SHALL FREESCALE OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 
* THE POSSIBILITY OF SUCH DAMAGE.
*
**************************************************************************
*
* $FileName: mpc83xx_etsec_stop.c$
* $Version : 3.8.1.0$
* $Date    : May-12-2011$
*
* Comments:
*
*            This file contains the QUICC Ethernet shutdown
*            functions.
*
*END************************************************************************/

#include <mqx.h>
#include <bsp.h>
#include <enet.h>
#include <enetprv.h>
#include <mpc83xx_etsec_prv.h>

/*FUNCTION*-------------------------------------------------------------
*
*  Function Name  : MPC83xx_etsec_shutdown
*  Returned Value : ENET_OK or error code
*  Comments       :
*        Stops the chip.
*
*END*-----------------------------------------------------------------*/

uint_32 MPC83xx_etsec_shutdown
   (
      /* [IN] the Ethernet state structure */
      ENET_CONTEXT_STRUCT_PTR   enet_ptr
   )
{ /* Body */
   MPC83XX_TSEC_CONTEXT_STRUCT_PTR  tsec_context_ptr=(MPC83XX_TSEC_CONTEXT_STRUCT_PTR)enet_ptr->MAC_CONTEXT_PTR;
   MPC83xx_ETSEC_STRUCT_PTR         tsec_ptr = tsec_context_ptr->TSEC_ADDRESS;
   uint_32                          error = ENET_OK;
   uint_32                          maccfg1;
   
   
   /* Enable RX and Tx */
   maccfg1 = tsec_ptr->MACCFG1;
   maccfg1 &= ~(MPC83xx_TSEC_MACCFG1_RX_ENABLE | MPC83xx_TSEC_MACCFG1_TX_ENABLE);
   TSEC_WRITE(tsec_ptr->MACCFG1, maccfg1);

   // Disable interrupts at TSEC level
   TSEC_WRITE(tsec_ptr->IMASK,  0);

   MPC83xx_etsec_uninstall_all_isrs(enet_ptr);

    /*
    ** Make sure all PCBs are free
    */
    if (tsec_context_ptr->ActiveRxBDs != tsec_context_ptr->NumRxBDs) {
       return ENETERR_FREE_PCB;
    } 

   MPC83xx_etsec_free_context(tsec_context_ptr);
 
   return error;
}

/* EOF */
